﻿
using System;
namespace Asteroids.Entities
{
    /// <summary>
    /// Provides a polymorphic way to process entities and their components to do various actions.
    /// </summary>
    public abstract class EntityProcessor : IDisposable
    {
        #region Fields

        private bool _sleepProcessor;

        #endregion

        /// <summary>
        /// Initializes a new instance of <see cref="Xenon.Game.Entities.EntityProcessor"/>
        /// </summary>
        public EntityProcessor()
        { _sleepProcessor = false; }

        ~EntityProcessor()
        { Dispose(false); }

        public void Dispose()
        { Dispose(true); }


        protected virtual void Dispose(bool disposing)
        { }

        /// <summary>
        /// Sets up the <see cref="Xenon.Game.Entities.EntityProcessor"/> to being processing an entity
        /// </summary>
        /// <param name="manager"></param>
        public virtual void Begin(EntityManager manager) 
        { }

        /// <summary>
        /// Cleans up this instance of <see cref="Xenon.Game.Entities.EntityProcessor"/> after processing an entity
        /// </summary>
        public virtual void End() 
        { }

        public virtual void Update(float delta) 
        { }

        /// <summary>
        /// Processes an <see cref="Xenon.Game.Entities.Entity"/>
        /// </summary>
        /// <param name="e"></param>
        public abstract void Process(Entity e);

        public override bool Equals(object obj)
        {
            return obj is EntityProcessor && 
                (obj as EntityProcessor).GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        { return GetType().GetHashCode(); }

        /// <summary>
        /// Get or set if this <see cref="Xenon.Game.Entities.EntityProcessor"/> should be ignored when the manager runs an update
        /// </summary>
        public bool ShouldSleep
        { 
            get { return _sleepProcessor; }
            set { _sleepProcessor = value; }
        }
    }
}
